<?php

namespace App\Admin\Renderable;

use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use App\Models\WorkUserHistory;
use Illuminate\Support\Facades\DB;

class WorkUserHistoryDetails extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new WorkUserHistory(), function (Grid $grid) {

            $grid->model()->where('id_card', $this->payload['id_card']);
            $grid->column('name','姓名');
            $grid->column('engineering','所属工地');
            $grid->column('type','类型')->display(function ($type) {
                if($type == 1){
                    return "<span style='color:red'>首次入职</span>";
                }
                if($type == 2){
                    return "<span style='color:red'>离职</span>";
                }
                if($type == 3){
                    return "<span style='color:red'>再入职</span>";
                }
                if($type == 4){
                    return "<span style='color:red'>劣迹</span>";
                }
            });
            $grid->column('details','轨迹')->display(function ($details) {
                if($this->type == 4){
                    return DB::table('misdeed')->where('id',$details)->value('name');
                }else{
                    return $details;
                }
            });



            $grid->column('enter_time','入职时间');
            $grid->column('exit_time','离职时间');
            $grid->column('created_at','轨迹产生时间');

//            $grid->disableCreateButton();
//            $grid->disableViewButton();
//            $grid->disableEditButton();

            $grid->disableActions();
//            $grid->column('enter_time','入职时间');
//            $grid->column('exit_time','离职时间');
//            $grid->quickSearch(['id', 'name', 'id_card']);
//            $grid->paginate(10);
//            $grid->filter(function (Grid\Filter $filter) {
//                $filter->like('username')->width(4);
//                $filter->like('name')->width(4);
//            });

        });
    }
}
